<?php

//function smarty_function_bbcode($params, &$smarty){
//    $text = $params['text'];
//    $bbcode = array(
//        "[list]", "[*]", "[/list]", //1
//        "[img]", "[/img]", //2
//        "[b]", "[/b]", //3
//        "[u]", "[/u]", //4
//        "[i]", "[/i]", //5
//        "[mail=\"", "[/mail]", //6
//        "[code]", "[/code]", //7
//        "[quote]", "[/quote]", //8
//        "<br />", //9
//        ":D", //10
//        ":(", //11
//        ":O", //12
//        ":P", //13
//        ";)", //14
//        ":)", //15
//        "<3"
//    );
//
//    $html = array(
//        "<li>", "[*]", "</li>", //1
//        "<img src=\"", "\" />", //2
//        "<b>", "</b>", //3
//        "<u>", "</u>", //4
//        "<i>", "</i>", //5
//        "<a href=\"mailto:", "</a>", //6
//        "<code>", "</code>", //7
//        "", "", //8
//        "", //9
//        '<img src="' . $tema . '/images/emoticon-happy.png" />', //10
//        '<img src="' . $tema . '/images/emoticon-unhappy.png" />', //11
//        '<img src="' . $tema . '/images/emoticon-surprised.png" />', //12
//        '<img src="' . $tema . '/images/emoticon-tongue.png" />', //13
//        '<img src="' . $tema . '/images/emoticon-wink.png" />', //14
//        '<img src="' . $tema . '/images/emoticon-smile.png" />', //15
//        '♥'
//    );
//
//    $text = str_replace($bbcode, $html, $str);
//    $text = nl2br($text);
//    $text = preg_replace('|\[url=(.*?)\](.*?)\[/url\]|si', '<a target="_blank" href="\\1">\\2</a>', $text);
//    $text = preg_replace('|\[color=(.*?)\](.*?)\[/color\]|si', '<span style="color:\\1">\\2</span>', $text);
//    $text = preg_replace('|\[size=(.*?)\](.*?)\[/size\]|si', '<span style="font-size:\\1px">\\2</span>', $text);
//    return $text;
//}



function smarty_function_bbcode($params, &$smarty) {
    $text = $params['text'];
    $tema = $params['tema'];

    if (!isset($text) && !isset($tema)) {
        $smarty->trigger_error("gravatar: neither 'email' nor 'default' attribute passed");
        return;
    }
    $bbcode = array(
        "[list]", "[*]", "[/list]", //1
        "[img]", "[/img]", //2
        "[b]", "[/b]", //3
        "[u]", "[/u]", //4
        "[i]", "[/i]", //5
        "[mail=\"", "[/mail]", //6
        "[code]", "[/code]", //7
        "[quote]", "[/quote]", //8
        "<br />", //9
        ":D", //10
        ":(", //11
        ":O", //12
        ":P", //13
        ";)", //14
        ":)", //15
        "<3"
    );

    $html = array(
        "<li>", "[*]", "</li>", //1
        "<img src=\"", "\" />", //2
        "<b>", "</b>", //3
        "<u>", "</u>", //4
        "<i>", "</i>", //5
        "<a href=\"mailto:", "</a>", //6
        "<code>", "</code>", //7
        "", "", //8
        "", //9
        '<img src="' . $tema . '/images/emoticon-happy.png" />', //10
        '<img src="' . $tema . '/images/emoticon-unhappy.png" />', //11
        '<img src="' . $tema . '/images/emoticon-surprised.png" />', //12
        '<img src="' . $tema . '/images/emoticon-tongue.png" />', //13
        '<img src="' . $tema . '/images/emoticon-wink.png" />', //14
        '<img src="' . $tema . '/images/emoticon-smile.png" />', //15
        '♥'
    );

    $text = str_replace($bbcode, $html, $text);
    $text = nl2br($text);
    $text = preg_replace('|\[url=(.*?)\](.*?)\[/url\]|si', '<a target="_blank" href="\\1">\\2</a>', $text);
    $text = preg_replace('|\[color=(.*?)\](.*?)\[/color\]|si', '<span style="color:\\1">\\2</span>', $text);
    $text = preg_replace('|\[size=(.*?)\](.*?)\[/size\]|si', '<span style="font-size:\\1px">\\2</span>', $text);
    return $text;
}

?>
